package com.jt.config;

import com.jt.vo.SysResult;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//问题:全局异常的处理 应该拦截哪一层的代码
//@ControllerAdvice+@RequestBody  //拦截controller层的异常
@RestControllerAdvice  //全局异常的处理 返回值为JSON
public class MyExceptionConfig {

    //问题2:嘛时候调用? 有异常的时候调用
    @ExceptionHandler(RuntimeException.class)
    public Object handler(Exception exception){
        //将报错信息在控制台打印
        exception.printStackTrace();
        return SysResult.fail();
    }
}
